<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Report</title>
</head>

<body>
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
    <script type="text/javascript">
        let URL = "http://s2.v3.hignton.com:9080/webroot/decision"

        window.onload = function() {
            try {
                let userInfo = localStorage.getItem("userInfo");
                userInfo = JSON.parse(userInfo)
                let telephone = userInfo.telephone
                getToken(telephone);
            } catch (e) {
                alert("未获取到用户登录状态");
                window.location.href = URL
            }
        }

        function getToken(telephone) {
            let url = "http://s2.v3.hignton.com:9080/iot_common/auth/getUserRepToken";
            $.ajax({
                url: url,
                data: {
                    telephone: telephone
                },
                success: function(res) {
                    if (res.status === 200) {
                        Login(res.data.token)
                    } else {
                        alert(res.message)
                    }
                },
                error: function() {
                    alert("超时或服务器其他错误"); // 登录失败（超时或服务器其他错误）
                }
            });
        }

        function Login(Thirdtoken) {
            var url = "http://s2.v3.hignton.com:9080/webroot/decision/third/auth/cross/login";
            $.ajax({
                url: url,
                dataType: "jsonp",
                data: {
                    third_token: Thirdtoken
                },
                success: function(res) {
                    if (res.errorCode) {
                        window.alert(res.errorMsg);
                    } else {
                        let href = URL + "?third_token=" + Thirdtoken;
                        window.location.href = URL + "?third_token=" + res.accesssToken
                    }
                },
                error: function() {
                    alert("超时或服务器其他错误"); // 登录失败（超时或服务器其他错误）
                }
            });
        }
    </script>
</body>

</html>